package com.demo.base;

/**
 * Created by xiaoyu on 2017/3/10.
 */
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class BaseServiceSupport<T> {
    private IMapper<T> mapper;

    public BaseServiceSupport() {
    }

    public static Map parseCountMap(Map paramMap) {
        if (paramMap == null) {
            return paramMap;
        } else {
            HashMap countParaMap = new HashMap();
            countParaMap.putAll(paramMap);
            countParaMap.remove("pageModel");
            return countParaMap;
        }
    }

    public abstract IMapper<T> getMapper();

    public abstract String getPK();

    public List<T> list(Map paramMap) {
        return this.getMapper().query(paramMap);
    }

    public int count(Map paramMap) {
        return this.getMapper().count(paramMap);
    }

    public void resetMapper(IMapper<T> mapper) {
        this.mapper = mapper;
    }

    public T add(T srcEntity) {
        int count = this.getMapper().insert(srcEntity);
        return count > 0 ? srcEntity : null;
    }

    public T edit(T srcEntity) {
        int count = this.getMapper().update(srcEntity);
        return count > 0 ? srcEntity : null;
    }

    public int del(T srcEntity) {
        return this.getMapper().delete(srcEntity);
    }

    public T findByMap(Map paramMap) {
        return this.getMapper().getInfoByMap(paramMap);
    }

    public T findByUuid(String uuid) {
        return this.getMapper().getInfoByUuid(uuid);
    }

}